// 这份代码专门处理逻辑层的操作
const fileDao = require('../dao/fileDao');

// const powerService = require('./powerService');

const fileService = {
    // 创建上传节点
    async createFileNode() {
        let result;
        try {
            let data = await fileDao.createFileNode();
            result = { success: true, data: data.insertId };
        } catch (err) {
            result = { success: false, msg: "数据库异常" };
        }
        return result;
    },
    // 获取上传预签名URL
    async getUploadUrl(imgId) {
        let result;
        try {
            let data = await fileDao.getUploadUrl(imgId);
            result = { success: true, data };
        } catch (err) {
            result = { success: false, msg: "数据库异常" };
        }
        return result;
    },
    // 标记图片上传完成
    async markUploadComplete(imgId) {
        let result;
        try {
            await fileDao.markUploadComplete(imgId);
            result = { success: true, msg: "标记成功" };
        } catch (err) {
            result = { success: false, msg: "数据库异常" };
        }
        return result;
    },
    // 下载文件
    async downloadPublicFile(fileId, uid) {
        let result;
        try {
            result = await fileDao.downloadPublicFile(fileId);
            result = { success: result.success, data: result };
        } catch (err) {
            result = { success: false, msg: "数据库异常" };
        }
        return result;
    }
};

module.exports = fileService;